﻿/// <reference path="jquery-1.7.1-vsdoc.js" />
/// <reference path="MyLibrary.js" />
/// <reference path="MyAjax.js" />

var i1 = 0; i2 = 0, i3 = 0, i4 = 0, i5 = 0;


Aobject.prototype.get = function () {
    return this.getP();
}


var object = new Aobject();
//alert(object.getPP());  //由于后来声明的  所以现在是不能访问的。

Aobject.prototype.getPP = function () {
    return this.getP() + 1;
};

function operate()
{

}
           var encodeValue = encodeURIComponent(value);
            //            x.setHeader("Accept", "*/*");
            //            x.setHeader("Accept-Charset", "GB2312,utf-8;q=0.7,*;q=0.7");
            //            x.setHeader("Accept-Encoding", "gzip, deflate");
            //            x.setHeader("Accept-Language", "zh-cn,zh;q=0.5");
            //            x.setHeader("Cookie", "	BAIDUID=43B8D1840AE64E53E11146F2EF1B7B22:FG=1");
            //            x.setHeader("Host", "suggestion.baidu.com");
            ////            x.setHeader("Host", "suggestion.baidu.com");
            ////            x.setHeader("Host", "suggestion.baidu.com");
            //            x.setData({ wd: encodeValue,
            //                cb: "window.bdsug.sug",
            //                p: "p",
            //                t: "1322810392789"
            //            });
//            x.setData({ client: "hp", hl: 'zh_CN', gs_is: "1", cp: "1", gs_id: "3h", q: encodeValue, xhr: "t" });


var x = new A();
x.setDefault("http://www.suggestion.baidu.com/su");
//alert(object.getPP());
//x.setOnReadyStateChange(x.stateChange);

x.success = function (text, headers) {
    var header = headers;
    //alert(text);
}
x.setData({wd:});
//$(document).ready(function () {



//    //alert((new Aobject()).get());

//    //    var date1 = new Date().getTime();
//    //    var result = fibonacci1()(30);
//    //    var time = new Date().getTime() - date1;
//    //    $("<div></div>").html(result + "<br />" + time + "<br />" + i1).appendTo($("body"));
//    //    var date1 = new Date().getTime();
//    //    var result = fibonacci2()(30);
//    //    var time = new Date().getTime() - date1;
//    //    $("<div></div>").html(result + "<br />" + time + "<br />" + i2).appendTo($("body"));
//    //    var date1 = new Date().getTime();
//    //    var result = fibonacci3()(30);
//    //    var time = new Date().getTime() - date1;
//    //    $("<div></div>").html(result + "<br />" + time + "<br />" + i3).appendTo($("body"));
//    //    var date1 = new Date().getTime();
//    //    var fun = fibonacci4()(30);
//    //    var result = fibonacci4()(30);
//    //    var time = new Date().getTime() - date1;
//    //    $("<div></div>").html(result + "<br />" + time + "<br />" + i4).appendTo($("body"));
//    //    var date1 = new Date().getTime();
//    //    var result = fibonacci5(30);
//    //    var time = new Date().getTime() - date1;
//    //    $("<div></div>").html(result + "<br />" + time + "<br />" + i5).appendTo($("body"));

//});


function Aobject() {  //这种函数或者是对象的声明构造函数，放到任何地方程序都能找的到。
    var private = 1;
    this.getP = function () {
        return private;
    };
}


function question(n) {

    return n == 1 ? 5 : 6 + 4;

}

function fibonacci1() {
    var process = new Array();
    return function (n) {
        i1++;
        if (!(typeof process[n] == "number")) {
            process[n] = n < 3 ? 1 : (typeof process[n - 1] == "number" ? process[n - 1] : fibonacci1()(n - 1)) + (typeof process[n - 2] == "number" ? process[n - 2] : fibonacci1()(n - 2));
        }
        return process[n];
    }
}

function fibonacci2() {

    var process = new Array();
    return function (n) {
        i2++;
        if (!(typeof process[n] == "number")) {
            if (n < 3) return 1;
            var n1 = typeof process[n - 1] == "number" ? process[n - 1] : fibonacci2()(n - 1);
            var n2 = typeof process[n - 2] == "number" ? process[n - 2] : fibonacci2()(n - 2);
            process[n - 1] = n1;
            process[n - 2] = n2;
            process[n] = n < 3 ? 1 : n1 + n2;
            //process[n] = n < 3 ? 1 : fibonacci()(n - 1) + fibonacci()(n - 2);
        }
        return process[n];
    }
}


function fibonacci3() {
    var process = new Array();
    return function (n) {
        i3++;
        if (!(typeof process[n] == "number")) {
            process[n] = n < 3 ? 1 : fibonacci3()(n - 1) + fibonacci3()(n - 2);
        }
        return process[n];
    }
}


function fibonacci4() {
    var memo = { 0: 0, 1: 0 };         //计算结果缓存
    var shell = function (n) {
        i4++;
        var result = memo[n];
        if (typeof result != 'number')    //如果值没有被计算则进行计算
            memo[n] = shell(n - 1) + shell(n - 2)
        return memo[n];
    }
    return shell;
}

function fibonacci5(n) {
    i5++;
    return n < 2 ? n : fibonacci5(n - 1) + fibonacci5(n - 2);
};

//function fibonacci() {
//    var process = new Array();
//    return function (n) {
//        if (!(typeof process[n] == "number")) {
//            process[n] = n < 3 ? 1 : (typeof process[n - 1] == "number" ? process[n - 1] : fibonacci()(n - 1)) + (typeof process[n - 2] == "number" ? process[n - 2] : fibonacci()(n - 2));
//        }
//        return process[n];
//    }
//}